import 'package:fluent_ui/fluent_ui.dart';
import 'package:fnos_tv_desktop/core/api/bean/media_info_result.dart';
import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';

import '../core/api/api.dart';
import '../core/model/categories.dart';
import '../core/model/media_databases.dart';
import '../core/model/user_info.dart';
import '../view/login/login_page.dart';
import '../view/main/main_page.dart';

class Nav {
  Nav._();

  static final GlobalKey<NavigatorState> navKey = GlobalKey();

  static const home = '/main';
  static const login = '/login';
  static const details = '/details';
  static const play = '/play';
  static const settings = '/settings';

  static const initialRoute = login;

  static final routes = {
    '/main': (context) => const MainPage(),
    '/login': (context) => const LoginPage(),
  };

  static void logout() {
    Api.logout();
    final context = navKey.currentContext!;
    context.read<UserInfo>().clear();
    context.read<MediaDatabases>().clear();
    context.read<Categories>().clear();
    navKey.currentState?.popUntil(ModalRoute.withName(login));
  }

  static Future<dynamic> goToDetails(MediaInfoResult info) async {
    await navKey.currentState?.pushNamed(details);
  }

  static Future<dynamic> goToPlay(MediaInfoResult info) async {
    await navKey.currentState?.pushNamed(play);
  }
}
